package com.miao.sqlSession;

import com.miao.config.XMLConfigBuilder;
import com.miao.pojo.Configuration;
import org.dom4j.DocumentException;

import java.io.InputStream;

/**
 * @author 喵瑞恒
 * @date 2023/09/13 20:43
 **/
public class SqlSessionFactoryBuilder {

    /**
     * 1.解析配置文件，封装容器对象
     * 2.创建SqlSessionFactory对象
     *
     * @param inputStream
     * @return
     */
    public SqlSessionFactory build(InputStream inputStream) throws DocumentException {
        //1.解析配置文件，封装容器对象
        XMLConfigBuilder xmlConfigBuilder = new XMLConfigBuilder();
        Configuration configuration = xmlConfigBuilder.parse(inputStream);

        //2.创建SqlSessionFactory工厂对象
        DefaultSqlSessionFactory defaultSqlSessionFactory = new DefaultSqlSessionFactory(configuration);
        return defaultSqlSessionFactory;

    }
}
